package com.nf.action;

import com.nf.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserAction extends ActionSupport implements ModelDriven<User> {

    private User user = new User();
    public User getUser() {
        System.out.println("getUser被调用了");
        return user;
    }

    public void setUser(User user) {
        System.out.println("setUser被调用了");
        this.user = user;
    }

    //登录用的
    public String login(){
        System.out.println("用户名:"+user.getUserName());
        if ("admin".equals(user.getUserName())&&"123456".equals(user.getUserPassword())){
            return this.SUCCESS;
        }else {
            return this.ERROR;
        }
    }

    public String loginView(){
        return this.SUCCESS;
    }

    public User getModel() {
        //告诉struts，你帮我对user进行赋值
        System.out.println("struts 调用我们的getModel，获得user的实例");
        return this.user;
    }
}
